package com.spring.lesson001.demo11.applicationcontextaware;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author vhans
 */
public class ServiceB implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    public void say() {
        ServiceA serviceA = this.getServiceA();
        System.out.println("this:"+this+",ServiceA:"+serviceA);
    }

    public ServiceA getServiceA() {
        return this.applicationContext.getBean(ServiceA.class);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
